<template>
	<view class="wrap1">
		<image class="bgs" src="https://wuyouzhuanapp.oss-cn-beijing.aliyuncs.com/1.png" mode=""></image>


		<u-sticky >
			<!-- 只能有一个根元素 -->
			<view class="sticky">
				<u-tabs bg-color="#fff" bar-width="96" inactive-color='#666666' bar-height="5" active-color="#333"
					:list="tablist" :is-scroll="false" :current="current" @change="change"></u-tabs>
			</view>
		</u-sticky>


		<view class="datas">
			
			<view v-if="list1.length">
				<list :list1="list1" />
				<uni-load-more :status="status"></uni-load-more>
			</view>
			
			<view v-else class="empty" style="padding-top: 150px;">
				<view v-if="!list1.length && senDate" class="emptyAddress-box">
					<u-empty text="暂无内容" mode="news"></u-empty>
				</view>
			</view>
			<!-- <list :current="current" /> -->
		</view>
		<!-- 无数据 -->
		<!-- <u-empty text="暂无数据" mode="data"></u-empty> -->
	</view>

</template>
<script>
	import list from '../list.vue'
	export default {
		components: {
			list
		},
		data() {
			return {
				tablist: [{
					name: '抖音任务'
				}, {
					name: '小红书任务'
				}, {
					name: '快手任务'
				}, {
					name: '咸鱼任务'
				}, {
					name: '视频号任务'
				}],
				current: 0,
				
				total: null, //总共多少条数据
				formData: {
					limit: 15, //每页10条数据
					page: 1, //第几页
					topic: "",
				},
				status: "more",
				senDate: false,
				list1: [],
				type:"dy",
				typeList:['dy','xhs','ks','xy','sph']
			};
		},
		onReachBottom() {
			let allTotal = this.formData.page * this.formData.limit;
			if (allTotal < this.total) {
				//当前条数小于总条数 则增加请求页数
				this.status = "loading"; //加载中状态
				this.formData.page++;
		
				this.getlist();
		
		
			} else {
				this.status = "noMore"; //加载完状态
				console.log("已加载全部数据");
			}
		},		
		onLoad(e) {
			this.type = e.type
				this.current = e.num*1
				this.formData.page = 1
				this.list1 = []
				this.getlist()
		},

		methods: {
			getlist() {
				this.senDate = false;
				this.$u.api
					.pageJobList({
						page: this.formData.page,
						limit: this.formData.limit,
						
						// "tab":1,// 1:新人任务, 2:每日必做
						tab: '',
						// "plat":"dy"  //平台：抖音：dy,快手:ks，小红书：xhs,咸鱼：xy, 视频号：sph
						
						plat:this.type //
					})
					.then((res) => {
			
						this.senDate = true;
						if (res.code == 0) {
			
							console.log(res.data, 666666);
							this.total = res.data.total;
							const newlist = res.data.list;
							this.list1.push(...newlist);
			
			
			
							this.list1 = res.data.list?.map(e => {
			
								let flag = undefined
								if (this.current == 0 && e.isAttention == 'Y') {
									flag = true
								}
								if (this.current == 1) {
									flag = true
								}
								return {
									...e,
									flag
								}
							})
			
			
							if (this.list1.length < this.formData.pageSize) {
								this.status = "noMore"; //加载完状态
							}
						} else {
							console.log("请求数据失败");
						}
					});
			},
			
			change(index) {
				this.current = index;
				this.type = this.typeList[index]
				
				this.formData.page = 1
				this.list1 = []
				this.getlist()
			},
			
		}
	};
</script>
<style lang="scss" scoped>
	// .sticky{
	// 	position: fixed;
	// 	top: 0;
	// 	left: 0;
	// 	right: 0;
	// 	z-index: 8;
	// }
	/deep/ .u-tab-bar {
		background: #3757FF !important;
	}

	// /deep/ .u-sticky-wrap {
	// 	background: none !important;
	// }

	.wrap1 {
		padding-bottom: 30rpx;
		.datas {
			margin: 30rpx 32rpx ;
			background: #fff;
			border-radius: 15rpx;
			padding: 32rpx;
			min-height: 85vh;

		}
	}
</style>
